const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
module.exports = {
  mode: "development",
  entry: './src/index.js',
  output: {
    filename: "[name]-[hash:8].js",
    path: path.resolve(__dirname, 'dist')
  },
  module: {
    rules: [
      {test: /\.css$/, use: ['style-loader', 'css-loader', 'postcss-loader']},
      {test: /\.less/i, use: ['style-loader', 'css-loader', 'less-loader']},
      {
        test: /\.jsx?/i,
        exclude: '/node_modules/',
        use: [
          {
            loader: "babel-loader", options: {
              presets: ['@babel/preset-env']
            }
          }
        ]
      }
    ]
  },
  devtool: "source-map",
  plugins: [
    new HtmlWebpackPlugin({
      title: "Webpack 测试配置",
      template: "./public/index.html"
    }),
    new CleanWebpackPlugin()
  ],
  devServer: {
    port: 8090,
    open: true
  }
};
